﻿using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace production.Forms
{
    public partial class buildProductionRatio : application.baseFormV2
    {
        public buildProductionRatio()
        {
            InitializeComponent();
        }
        Stopwatch myStopWatch = new Stopwatch();

        private void createTreeBtn_Click(object sender, EventArgs e)
        {
            try
            {
                myStopWatch.Reset();
                myStopWatch.Start();
                productionTree.Build();
                errorEd.Text = productionTree.GetErrorText();
                myStopWatch.Stop();
                this.ShowMessage(commonV2.dateTimeLibs.TimeSpan2String(myStopWatch.Elapsed));
                dataTabControl.SelectedTab = (errorEd.Text.Trim()==""?prodTreePg:errorPg);
            }
            catch (Exception er)
            {
                this.ErrorHandler(this,er);
            }
        }

        private void buildProdDbBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (commonV2.SysLibs.MessageBoxYESNO("Lưu dữ liệu định mức sẽ xóa bỏ dữ liệu cũ  ?") == DialogResult.No) return;
                myStopWatch.Reset();
                myStopWatch.Start();
                productionTree.Reset();
                productionTree.BuildProductionRatioDB();
                errorEd.Text = productionTree.GetErrorText();
                dataTabControl.SelectedTab = (errorEd.Text.Trim() == "" ? prodTreePg : errorPg);
                myStopWatch.Stop();
                this.ShowMessage(commonV2.dateTimeLibs.TimeSpan2String(myStopWatch.Elapsed));
                commonV2.SysLibs.ShowMessage("Đã lưu dữ liệu định mức.");
            }
            catch (Exception er)
            {
                this.ErrorHandler(this,er);
            }
        }
    }
}
